package com.jksj;

import lombok.Setter;

public class Join {
    public static final Object o = new Object();
    public static void main(String[] args) throws InterruptedException {

        MyThread myThread = new MyThread();
        myThread.setO(o);
        myThread.start();
        synchronized (myThread){
            for (int i = 0; i < 100; i++) {
                if(i==20){
                    myThread.join();  // 会释放 myRunnable 锁 内部是调用的wait()
                }
                System.out.println(Thread.currentThread().getName()+i);
            }
        }


    }
}
@Setter
class MyThread extends Thread {

    private Object o;


    @Override
    public void run() {

        synchronized (this) {
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + " " + i);
            }
        }
    }
}
